'''
Created on 2012-4-12

@author: Administrator
'''

from popcan.core.structures import Singleton
import cPickle,pickle,yaml
from cStringIO import StringIO

class CPickleHelper(Singleton):
    
    def dump(self,item):
        buf = StringIO()
        p = cPickle.Pickler(buf)
        p.dump(item)
        return buf.getvalue()
    
    def load(self,raw):
        buf = StringIO(raw)
        p = cPickle.Unpickler(buf)
        return p.load()
    
class PickleHelper(Singleton):
    
    def dump(self,item):
        buf = StringIO()
        p = pickle.Pickler(buf)
        p.dump(item)
        return buf.getvalue()
    
    def load(self,raw):
        buf = StringIO(raw)
        p = pickle.Unpickler(buf)
        return p.load()
    
class YamlHelper(Singleton):
    
    def dump(self,item):
        buf = StringIO()
        yaml.dump(item,buf)
        return buf.getvalue()
    
    def load(self,raw):
        buf = StringIO(raw)
        return yaml.load(buf)

